import java.util.HashSet;
import java.util.Set;

/**
 * @author LKQ
 * @date 2021/12/24 22:59
 * @description hashSet
 */
public class Solution2 {
    public static void main(String[] args) {

    }
    public int missingNumber(int[] nums) {
        Set<Integer> set = new HashSet<Integer>();
        int n = nums.length;
        // hash表中存储已经存在的值
        for (int i = 0; i < n; i++) {
            set.add(nums[i]);
        }
        int missing = -1;
        for (int i = 0; i <= n; i++) {
            if (!set.contains(i)) {
                missing = i;
                break;
            }
        }
        return missing;
    }

}
